/*
 * File: look2_iu8u16lu32tu16_binfcae.c
 *
 * Code generated for Simulink model 'SOPE'.
 *
 * Model version                  : 1.476
 * Simulink Coder version         : 9.0 (R2018b) 24-May-2018
 * C/C++ source code generated on : Mon Sep  7 13:15:40 2020
 */

#include "rtwtypes.h"
#include "look2_iu8u16lu32tu16_binfcae.h"

uint16_T look2_iu8u16lu32tu16_binfcae(uint8_T u0, uint16_T u1,
		const uint8_T bp0[], const uint16_T bp1[], const uint16_T table[],
		const uint32_T maxIndex[], uint32_T stride) {
	uint32_T bpIndices[2];
	uint32_T iRght;
	uint32_T bpIdx;
	uint32_T iLeft;

	/* Column-major Lookup 2-D
	 Search method: 'binary'
	 Use previous index: 'off'
	 Interpolation method: 'Flat'
	 Extrapolation method: 'Clip'
	 Use last breakpoint for index at or above upper limit: 'on'
	 Remove protection against out-of-range input in generated code: 'off'
	 */
	/* Prelookup - Index only
	 Index Search method: 'binary'
	 Extrapolation method: 'Clip'
	 Use previous index: 'off'
	 Use last breakpoint for index at or above upper limit: 'on'
	 Remove protection against out-of-range input in generated code: 'off'
	 */
	if (u0 <= bp0[0U]) {
		iLeft = 0U;
	} else if (u0 < bp0[maxIndex[0U]]) {
		/* Binary Search */
		bpIdx = maxIndex[0U] >> 1U;
		iLeft = 0U;
		iRght = maxIndex[0U];
		while (iRght - iLeft > 1U) {
			if (u0 < bp0[bpIdx]) {
				iRght = bpIdx;
			} else {
				iLeft = bpIdx;
			}

			bpIdx = (iRght + iLeft) >> 1U;
		}
	} else {
		iLeft = maxIndex[0U];
	}

	bpIndices[0U] = iLeft;

	/* Prelookup - Index only
	 Index Search method: 'binary'
	 Extrapolation method: 'Clip'
	 Use previous index: 'off'
	 Use last breakpoint for index at or above upper limit: 'on'
	 Remove protection against out-of-range input in generated code: 'off'
	 */
	if (u1 <= bp1[0U]) {
		iLeft = 0U;
	} else if (u1 < bp1[maxIndex[1U]]) {
		/* Binary Search */
		bpIdx = maxIndex[1U] >> 1U;
		iLeft = 0U;
		iRght = maxIndex[1U];
		while (iRght - iLeft > 1U) {
			if (u1 < bp1[bpIdx]) {
				iRght = bpIdx;
			} else {
				iLeft = bpIdx;
			}

			bpIdx = (iRght + iLeft) >> 1U;
		}
	} else {
		iLeft = maxIndex[1U];
	}

	return table[iLeft * stride + bpIndices[0]];
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
